package com.whl.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.whl.mybatis.BaseMapper;
import com.whl.project.entity.UserEntity;

public interface UserMapper extends BaseMapper<UserEntity> {

	@Update("update user  set password = #{password} WHERE id = #{id}")
	public int updatePassword(@Param("id") Long id, @Param("password") String password);

	@Update("update user set own_id = null where id= #{id}")
	public void unbund(@Param("id") Long id);

	@Update("update user set enable = #{enable} where id= #{id}")
	public void changeEnable(@Param("id") Long id, @Param("enable") Boolean enable);

	@Update("update user_app set enable = #{enable} where user_id= #{userId} and app = #{app}")
	public void changeAppEnable(@Param("userId") Long userId, @Param("app") String app, @Param("enable") Boolean enable);

	public List<UserEntity> findByRoleCode(String roleCode);

	@Select("select * from user where email = #{email}")
	@ResultMap("baseResultMap")
	public UserEntity selectByEmail(String email);

	@Select("select * from user where mobile = #{mobile}")
	@ResultMap("baseResultMap")
	public UserEntity selectByMobile(String mobile);

	public UserEntity selectByAccount(@Param("account") String account);

	@Select("select * from user where nickname = #{nickname}")
	@ResultMap("baseResultMap")
	public UserEntity selectByNickname(String nickname);

	@Delete("delete from user_role where user_id = #{userId}")
	public void deleteUserRole(Long userId);

	@Select("select role_id from user_role where user_id = #{userId}")
	public List<Long> getUserRole(Long userId);

}
